package com.qianfeng.zhangwei.xytg.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.qianfeng.zhangwei.xytg.R;
import com.qianfeng.zhangwei.xytg.bean.Good;
import com.qianfeng.zhangwei.xytg.constants.UrlConstants;
import com.qianfeng.zhangwei.xytg.utils.ImageLoaderHelper;

import java.util.List;

/**
 * @说 明：
 * @项目名称：Sz1504
 * @包 名： com.qianfeng.zhangwei.xytg.adapter
 * @类 名： GroupBuyAdapter
 * @创 建人： zhangwei
 * @创建时间：2015-07-24 22:57
 * @版 本：v1.0
 * @修 改人：
 * @修改时间：
 * @修改备注：
 */
public class GbGoodAdapter extends AppBaseAdapter<Good> {

    /**
     * @param list
     * @param context
     */
    public GbGoodAdapter(List<Good> list, Context context) {
        super(list, context);
        options = ImageLoaderHelper.getInstance().getDisplayImageOptions(R.mipmap.list_default, R.mipmap.list_default);
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        Good good = list.get(position);
        ViewHolder vh = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_gb_good_layout, parent, false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        } else {
            vh = (ViewHolder) convertView.getTag();
        }
        vh.titleTv.setText(good.getProduct());
        vh.productTv.setText(good.getSummary());
        vh.teamPriceTv.setText(new StringBuffer().append("¥ ").append(good.getTeam_price()).toString());
        vh.markPriceTv.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
        vh.markPriceTv.setText(good.getMarket_price());
        vh.nowNumberTv.setText("已售 " + good.getNow_number());
//        String distanceStr = String.valueOf((int) DistanceUtil.getDistance(new LatLng(BaseApp.getInstance().getLat(), BaseApp.getInstance().getLng()), new LatLng(Double.valueOf(good.getLat()), Double.valueOf(good.getLng()))) / 1000);
//        vh.distanceTv.setText(distanceStr + "千米");
        String imageUrl = UrlConstants.URL_IMAGE_STATIC + list.get(position).getImage();
        ImageLoader.getInstance().displayImage(imageUrl, vh.img, options);
        return convertView;
    }

    /**
     *
     */
    private static class ViewHolder {
        private ImageView img;
        private TextView titleTv, distanceTv, productTv, teamPriceTv, markPriceTv, nowNumberTv;

        public ViewHolder(View view) {
            this.img = (ImageView) view.findViewById(R.id.item_gb_img);
            titleTv = (TextView) view.findViewById(R.id.item_gb_title);
            distanceTv = (TextView) view.findViewById(R.id.item_gb_distance);
            productTv = (TextView) view.findViewById(R.id.item_gb_product);
            teamPriceTv = (TextView) view.findViewById(R.id.item_gb_team_price);
            markPriceTv = (TextView) view.findViewById(R.id.item_gb_market_price);
            nowNumberTv = (TextView) view.findViewById(R.id.item_gb_now_number);
        }
    }

}
